package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button remove;

    private FragmentManager manager;
    private BlankFragment blankFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        remove = (Button) findViewById(R.id.remove);

         manager = getSupportFragmentManager();
        //开始事务
        final FragmentTransaction fragmentTransaction = manager.beginTransaction();
        /**
         * 容器的id
         * fragment对象
         */
         blankFragment = new BlankFragment();
//        BlankFragment blankFragment1 = new BlankFragment();
//        BlankFragment blankFragment2 = new BlankFragment();
//        BlankFragment blankFragment3 = new BlankFragment();
        //添加
        fragmentTransaction.add(R.id.ll,blankFragment);
//        fragmentTransaction.replace(R.id.ll,blankFragment3);
//        fragmentTransaction.hide(blankFragment2);

        //提交
        fragmentTransaction.commit();

        remove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentTransaction fragmentTransaction1 = manager.beginTransaction();
//                fragmentTransaction1.remove(blankFragment);
                fragmentTransaction1.hide(blankFragment);
                fragmentTransaction1.commit();
            }
        });

    }

    public void show(View view) {
        FragmentTransaction fragmentTransaction1 = manager.beginTransaction();
//                fragmentTransaction1.remove(blankFragment);
        fragmentTransaction1.show(blankFragment);
        fragmentTransaction1.commit();
    }
}
